import java.util.UUID;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author Stringzhua
 * @Date 2024/10/31 10:04
 * description:
 */
public class Demo01 {
    public static void main(String[] args) {
        ExecutorService poolExecutor = new ThreadPoolExecutor(0, 1024, 60L,
                TimeUnit.SECONDS, new SynchronousQueue<>(), new MyFactory(), new ThreadPoolExecutor.DiscardPolicy());

        for (int i = 0; i <= 100000; i++) {
            poolExecutor.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName() + "==>" + UUID.randomUUID());

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }

        poolExecutor.shutdown();
    }
}

class MyFactory implements ThreadFactory {
    private String prefix;
    private final AtomicInteger threadNum = new AtomicInteger(0);

    public MyFactory() {
        this.prefix = "优惠券秒杀";
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread t = new Thread(r, prefix + threadNum.incrementAndGet());
        return t;
    }
}
